package main

import (
	"time"

	"github.com/jinzhu/gorm"
)

type Device struct {
	gorm.Model
	App     App `gorm:"ForeignKey:AppID"`
	AppID   uint
	Name    string `gorm:"size:256"`
	ChipId  string `gorm:"size:64"`
	DevUuid string `gorm:"size:64"`
	Latest  time.Time
	Stat    string `gorm:"size:16"`
}

type DeviceAttr struct {
	ID        uint   `gorm:"primary_key"`
	Device    Device `gorm:"ForeignKey:DeviceID"`
	DeviceID  int
	CreatedAt time.Time
	Key       string `gorm:"size:512"`
	Value     string `gorm:"type:text"`
}

type App struct {
	gorm.Model
	user   User `gorm:"ForeignKey:UserID"`
	UserID uint
	Name   string `gorm:"size:128"`
	AppKey string `gorm:"size:256"`
	Note   string `gorm:"size:512"`
	Stat   string `gorm:"size:16"`
}

type CoapSession struct {
	gorm.Model
	Device   Device `gorm:"ForeignKey:DeviceID"`
	DeviceID int
	Token    string `gorm:"size:16"`
	Stat     string `gorm:"size:16"`
}

type User struct {
	gorm.Model
	Email     string `gorm:"size:128"`
	Avatar    string `gorm:"size:512"`
	LastLogin time.Time
	Password  string `gorm:"size:128"`
	Stat      string `gorm:"size:16"`
}

type UserAuthToken struct {
	gorm.Model
	User   User `gorm:"ForeignKey:UserID"`
	UserID int
	Expire int
	Token  string `gorm:"size:128"`
	Stat   string `gorm:"size:16"`
}
